#include "StdAfx.h"
#include "LitEditorLogger.h"
#include <OgreLogManager.h>

namespace Lit
{
	namespace Editor
	{
		void Logger::messageLogged( const Ogre::String &msg, Ogre::LogMessageLevel lml, bool mask_debug, const Ogre::String &log_name, bool&skipThis )
		{
			logMessage( msg, false );
		}
		Logger::Logger( QDockWidget * dock ) : Initialiser( "Logger" ), mDock( dock ), mLog(NULL){
			mEdit = new QPlainTextEdit(dock);
			dock->setWidget( mEdit );
		}
		Logger::~Logger(){}
		
		RefPtr<Ogre::Log> Logger::data() const
		{
			return mLog;
		}
		void Logger::initialise( Ogre::Log * log ){
			throwAlreadyInit( );
			if( !log ) throw Lit::InvalidParameter( "Log", "null pointer", EXC_LOC );
			mLog = log;
			mLog->addListener(this);

			setInitialised( true );
		}
		void Logger::deInitialise(){
			throwNotInit( );
			if( !mLog ) return;
			mLog->removeListener( this );

			setInitialised( false );
		}
		void Logger::clear()
		{
			if( mEdit ) mEdit->clear();
		}

		QPlainTextEdit * Logger::getEditor(){ return mEdit; }
		const QPlainTextEdit * Logger::getEditor() const{ return mEdit; }

		void Logger::logMessage( const std::string &msg, bool ogre_log_too )
		{
			throwNotInit( );
			if( !mLog ) return;
			if( ogre_log_too )
				mLog->logMessage( msg );
			else mEdit->appendPlainText( TO_QT(msg) );
		}
	};
};